package cn.tedu.four.controller;

import cn.tedu.four.ex.ServiceException;
import cn.tedu.four.pojo.dto.AlbumAddNewDTO;
import cn.tedu.four.pojo.entity.Album;
import cn.tedu.four.pojo.vo.AlbumListItemVO;
import cn.tedu.four.service.AlbumService;
import cn.tedu.four.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.sql.rowset.serial.SerialException;
import javax.validation.Valid;
import java.util.List;

/**
 * ClassName: AlbumController
 * Package: cn.tedu.four.controller
 * Description:
 *
 * @Author: @Albert
 * @Version: 1.0
 */
@Api(tags = "01. 相册管理模块")
@RestController
@Validated
@RequestMapping("/album")
public class AlbumController {
    @Autowired
    AlbumService service;
    //http://localhost:8080/album/addNew?name="前端测试名称2"&sort=12&description="前端描述"

    @ApiOperationSupport(order = 10)
    @ApiOperation("添加相册方法")
    @PostMapping("/add-new")
    public JsonResult addNew(@Valid AlbumAddNewDTO album){
        System.out.println("album = " + album);
            service.addNew(album);
            return JsonResult.ok();
    }

    @ApiOperationSupport(order = 300)
    @ApiOperation("删除相册方法")
    @ApiImplicitParam(name="id",value="相册ID",dataType ="long")
    @PostMapping("/delete")
    public JsonResult delete(@Range(min = 1,message = "删除失败,输入的ID值无效") Long id){
        service.delete(id);
        return JsonResult.ok();
    }


    @ApiOperationSupport(order = 400)
    @ApiOperation("修改相册方法")
    @PostMapping("/update")
    public String update(AlbumAddNewDTO album){

        return "添加相册成功";
    }
    @ApiOperationSupport(order = 500)
    @ApiOperation("查询相册")
    @GetMapping("/list")
    public JsonResult list(){
        List<AlbumListItemVO> list = service.list();
        return JsonResult.ok(list);
    }


}
